package com.example.demo.repository;

import com.example.demo.po.Users;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Repository
public interface UserRepository extends JpaRepository<Users,Integer>, JpaSpecificationExecutor<Users> {
    @Query(value = "select * from users",nativeQuery = true)
    public List<Map> getAllUser();

    Users findByUsername(String username);

    @Query("select b from Users b where b.username = ?1")
    public List<Users> get_by_username(String username);

    @Modifying
    @Query("UPDATE Users u SET u.username = :username where u.id = :id")
    @Transactional
    Integer update_user(@Param("id") Integer id, @Param("username") String username);

}
